<template>
  <view >
    
	<view class="cart-container" v-if="cart.length!==0">
    <my-address></my-address>
		<view class="cart-title">
		 <uni-icons type="cart" size="18"></uni-icons>
     <text>购物车</text>
		</view>
  <!--  <my-goods :showNum="true" :showRadio="true" :goods="goods" v-for="(goods,i) in cart" :key="i" @radio-change="radioChangeHandler" @num-change="numchangeHandler"> </my-goods> -->
    
    <uni-swipe-action>
      <block v-for="(goods,i) in cart" :key="i" >
      <uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
        <my-goods :showNum="true" :showRadio="true" :goods="goods" @radio-change="radioChangeHandler" @num-change="numchangeHandler"> </my-goods>
      </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
        <my-settle></my-settle>
	</view>
  <view class="empty-cart-box" v-else>
    <image class="empty-img" src="/static/cart_empty@2x.png" ></image>
    <text class="tips-text">空空如也</text>
  </view>
  
  </view>
</template>

<script>
  import badgeMix  from '@/mixins/tabbar-badge.js'
  import {mapState,mapMutations} from 'vuex'
	export default {
    mixins:[badgeMix],
    computed:{
       ...mapState('m_cart',['cart'])
       
    },
    data(){
        return {
          options:[
            {
                text: '取消',
                style: {
                    backgroundColor: '#C00000' 
                }
            }
          ] 
        }
      },
    methods:{
      ...mapMutations('m_cart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
      radioChangeHandler(e){
        this.updateGoodsState(e)
      },
      numchangeHandler(e){
       this.updateGoodsCount(e)
      },
      swipeActionClickHandler(goods) {
      this.removeGoodsById(goods.goods_id)
      console.log(goods.goods_id)
      }
      
    }
   
	}
</script>

<style lang="scss">
  .cart-container{
    padding-bottom: 50px;
  }
.cart-title{
  height: 40px;
  padding-left: 5px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #efefef;
  uni-icons{
    margin-right: 5px;
  }
}
.empty-cart-box{
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;
  .empty-img{
    width: 90px;
    height: 90px;
  }
  .tips-text{
    font-size: 13px;
    color: grey;
  }
}
</style>
